package com.ygqh.baby.service.impl;
import java.util.List;
import  com.ygqh.baby.ao.QueryInfo;
import  com.ygqh.baby.ao.ResultSet;
import  com.ygqh.baby.po.AdminCustom;
import  com.ygqh.baby.mapper.AdminCustomMapper;
import  com.ygqh.baby.service.AdminCustomService;
import  org.springframework.util.Assert;
import java.util.Arrays;
import  org.springframework.stereotype.Service;
import  org.springframework.beans.factory.annotation.Autowired;

import  com.ygqh.baby.po.AdminCustomExample;
import  com.ygqh.baby.ao.DataStatus;

@Service
public class AdminCustomServiceImpl implements AdminCustomService{
	
	@Autowired
	private AdminCustomMapper adminCustomMapper;
	
	@Override
	public List<AdminCustom> find() {
		AdminCustomExample example = new AdminCustomExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminCustomMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		AdminCustomExample example = new AdminCustomExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminCustomMapper.countByExample(example);
	}

	@Override
	public AdminCustom findById(Long id) {
		return adminCustomMapper.selectByPrimaryKey(id);
	}


	

	@Override
	public int save(AdminCustom adminCustom) {
		return adminCustomMapper.insertSelective(adminCustom);
	}

	@Override
	public int update(AdminCustom adminCustom) {
		return adminCustomMapper.updateByPrimaryKeySelective(adminCustom);
	}

	@Override
	public ResultSet<AdminCustom> search(QueryInfo queryInfo,String q) {
		List<AdminCustom>  list =  adminCustomMapper.selectSuper(queryInfo, q);
		int count = adminCustomMapper.countSuper(q);
		ResultSet<AdminCustom> resultSet = new ResultSet<AdminCustom>(count,list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		AdminCustomExample example = new AdminCustomExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		AdminCustom record = new AdminCustom();
		record.setStatus(DataStatus.Delete);

		return adminCustomMapper.updateByExampleSelective(record, example);
	}
	
	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[]{id});
	}

	@Override
	public int saveOrUpdate(AdminCustom adminCustom) {
		int r = 0;
		if(adminCustom.getId() != null) {
			r = this.update(adminCustom);
		}else {
			r = this.save(adminCustom);
		}
		return r;
	}

}

